/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.yournamehere.client;

import com.smartgwt.client.data.Criteria;
import com.smartgwt.client.data.DataSource;
import com.smartgwt.client.types.DragDataAction;
import com.smartgwt.client.widgets.TransferImgButton;
import com.smartgwt.client.widgets.Window;
import com.smartgwt.client.widgets.events.ClickEvent;
import com.smartgwt.client.widgets.events.ClickHandler;
import com.smartgwt.client.widgets.form.DynamicForm;
import com.smartgwt.client.widgets.form.fields.SelectItem;
import com.smartgwt.client.widgets.form.fields.events.ChangedEvent;
import com.smartgwt.client.widgets.form.fields.events.ChangedHandler;
import com.smartgwt.client.widgets.grid.ListGrid;
import com.smartgwt.client.widgets.grid.ListGridField;
import com.smartgwt.client.widgets.layout.HStack;
import com.smartgwt.client.widgets.layout.LayoutSpacer;
import com.smartgwt.client.widgets.layout.VStack;

/**
 *
 * @author User
 */
public class fmrCurso extends Window{
    fmrCurso()
    {
        Init();
    }
    void Init()
    {
        setWidth("100%");
        setHeight("100%");
        setTitle("Cursos");

        
        String[] projects = new String[] {
                 "Base de Datos II", "Estructuras Avanzadas",
                 "Ingenieria de Software II", "Lenguajes de Programacion",
                 "Logina computacional","Sistemas Operativos"
         };


         DataSource employeesDS = EmployeeXmlDS.getInstance();
         final ListGrid employeesGrid = new ListGrid();
         employeesGrid.setWidth(300);
         employeesGrid.setHeight(224);
         employeesGrid.setDataSource(employeesDS);
         employeesGrid.setCanDragRecordsOut(true);
         employeesGrid.setDragDataAction(DragDataAction.COPY);
         employeesGrid.setAutoFetchData(false);

         ListGridField employeeIdField = new ListGridField("EmployeeId");
         employeeIdField.setWidth("25%");

         ListGridField nameField = new ListGridField("Name");

         employeesGrid.setFields(employeeIdField, nameField);


         DataSource teamMembersDS = TeamMembersXmlDS.getInstance();

         final ListGrid projectGrid = new ListGrid();
         projectGrid.setWidth(300);
         projectGrid.setHeight(264);
         projectGrid.setDataSource(teamMembersDS);
         projectGrid.setCanAcceptDroppedRecords(true);
         projectGrid.setCanRemoveRecords(true);
         projectGrid.setAutoFetchData(false);
         projectGrid.setPreventDuplicates(true);

         ListGridField employeeIdField2 = new ListGridField("employeeId");
         employeeIdField2.setWidth("20%");

         ListGridField employeeNameField2 = new ListGridField("employeeName");
         employeeNameField2.setWidth("40%");
         ListGridField projectCodeField2 = new ListGridField("projectCode");

         projectGrid.setFields(employeeIdField2, employeeNameField2, projectCodeField2);

         HStack hStack = new HStack(10);
         hStack.setHeight(160);

         VStack vStack = new VStack();
         LayoutSpacer spacer = new LayoutSpacer();
         spacer.setHeight(30);
         vStack.addMember(spacer);
         vStack.addMember(employeesGrid);

         hStack.addMember(vStack);

         TransferImgButton arrowImg = new TransferImgButton(TransferImgButton.RIGHT);
         arrowImg.addClickHandler(new ClickHandler() {
             public void onClick(ClickEvent event) {
                 projectGrid.transferSelectedData(employeesGrid);
             }
         });
         hStack.addMember(arrowImg);

         VStack vStack2 = new VStack();

         final DynamicForm projectSelectorForm = new DynamicForm();
         projectSelectorForm.setWidth(300);
         projectSelectorForm.setHeight(30);

         SelectItem selectItem = new SelectItem("projectCode", "Team for Project");
         selectItem.setDefaultValue(projects[0]);
         selectItem.setValueMap(projects);
         selectItem.addChangedHandler(new ChangedHandler() {
             public void onChanged(ChangedEvent event) {
                 Criteria criteria = projectSelectorForm.getValuesAsCriteria();
                 projectGrid.fetchData(criteria);
             }
         });
         projectSelectorForm.setFields(selectItem);

         vStack2.addMember(projectSelectorForm);
         vStack2.addMember(projectGrid);

         hStack.addMember(vStack2);

         projectGrid.fetchData(projectSelectorForm.getValuesAsCriteria());
         employeesGrid.fetchData();


         addItem(hStack);
         //hStack.draw();
    }

}
